<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--  百度cdn引入jquery  -->
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>

    <button id="btn1">get</button>
    <button id="btn2">post</button>
    <button id="btn3">put</button>
    <button id="btn4">delete</button>

    <script>

        $(function () {
            // 注册按钮单击事件
            $("#btn1").click(function () {
                //js对象
                $.ajax({
                    url:'/users',
                    type:'get',
                    success:function(ret){
                        console.log(ret);
                    }
                });
            });


            $("#btn2").click(function () {
                //js对象
                var user = {id:1,name:"揣明",birth:"2008-01-02 00:00:00",gender:false};
                $.ajax({
                    /*url:'/users?id=200&name=zhangsan&birth=1992-01-24 12:50:33',*/
                    url:'/users',
                    type:'post',
                    data:user,
                    success:function(ret){
                        console.log(ret);
                    }
                });

            });


            $("#btn3").click(function () {
                //js对象
                var user = {id:1,name:"揣明",birth:"2008-01-02 00:00:00",gender:false};
                $.ajax({
                    url:'/users',
                    type:'put',
                    contentType:"application/json",//声明请求参数类型为 json
                    data:JSON.stringify(user),// 转换js对象成json
                    success:function(ret){
                        console.log(ret);
                    }
                });
            });

            $("#btn4").click(function () {
                $.ajax({
                    url:'/users/1',
                    type:'delete',
                    success:function(ret){
                        console.log(ret);
                    }
                });
            });
        });

    </script>

</body>
</html>
